package com.atguigu.gmall.product.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Api(tags = "前端商品管理")
@RestController
@RequestMapping("/api/product")
public class ProductApiController {
//    /api/product/inner/getSkuInfo/{skuId}
    @Autowired
    private ManageService manageService;

    //根据skuId获取sku信息 + skuImageList信息
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getAttrValueList(@PathVariable Long skuId){
        SkuInfo skuInfo = manageService.getSkuInfo(skuId);
        return skuInfo;
    }
//    api/product/inner/getSkuPrice/{skuId}
    @GetMapping("/inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId){
      return manageService.getSkuPrice(skuId);

    }
//    api/product/inner/getCategoryView/{category3Id}
//    根据三级分类id查询获取分类信息
    @GetMapping("inner/getCategoryView/{category3Id}")
    public BaseCategoryView  getCategoryView(@PathVariable Long category3Id){
        return manageService.getCategoryViewByCategory3Id(category3Id);
    }
//    根据spuId，skuId 查询销售属性集合 api/product/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}
    @GetMapping("inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrList(@PathVariable("skuId") Long skuId,
                                                @PathVariable("spuId") Long spuId){
        return manageService.getSpuSaleAttrListCheckBySku(skuId,spuId);
    }
    //根据spuId查询map的集合属性
    @GetMapping("inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable("spuId") Long spuId){
        return manageService.getSkuValueIdsMap(spuId);
    }
    //根据spuId获取海报数据inner/findSpuPosterBySpuId/{spuId}
    @GetMapping("inner/findSpuPosterBySpuId/{spuId}")
    public List<SpuPoster> findSpuPosterBySpuId(@PathVariable Long spuId){
        return  manageService.findSpuPosterBySpuId(spuId);
    }
//    /api/product/inner/getAttrList/{skuId}
    @GetMapping("inner/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable Long skuId){
       return manageService.getAttrList(skuId);
    }

    /**
     * 获取全部分类信息
     * @return
     */
    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList(){
        List<JSONObject> list = manageService.getCategoryList();
        return Result.ok(list);
    }
    //    根据品牌id获取获取品牌数据
    @GetMapping("inner/getTrademark/{tmId}")
    public BaseTrademark getTrademark(@PathVariable Long tmId){
        return manageService.getTrademark(tmId);
    }
}